import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  { path: "/", redirect: "/login" },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/login.vue"),
  },
  {
    path: "/iphone",
    name: "iphone",
    component: () => import("../views/iphone.vue"),
  },
  {
    path: "/qrcode",
    name: "qrcode",
    component: () => import("../views/qrcode.vue"),
  },

  {
    path: "/home",
    name: "home",
    component: () => import("../views/home.vue"),
    children: [
      {
        path: "home2",
        name: "home2",
        component: () => import("../views/home2.vue"),
      },
      {
        path: "my",
        name: "my",
        component: () => import("../views/my.vue"),
      },
      {
        path: "music",
        name: "music",
        component: () => import("../views/music.vue"),
      },
    ],
  },

  // {
  //   path: "/home",
  //   name: "home",
  //   component: () => import("../views/home.vue"),
  //   children: [
  //     {
  //       path: "home2",
  //       name: "home2",
  //       component: () => import("../views/home2.vue"),
  //     },
  //     {
  //       path: "my",
  //       name: "my",
  //       component: () => import("../views/my.vue"),
  //     },
  //     {
  //       path: "music",
  //       name: "music",
  //       component: () => import("../views/music.vue"),
  //     },
  //   ],
  // },

  // {
  //   path: "/home2",
  //   name: "home2",
  //   component: () => import("../views/home2.vue"),
  // },
  // {
  //   path: "/my",
  //   name: "my",
  //   component: () => import("../views/my.vue"),
  // },
  // {
  //   path: "/music",
  //   name: "music",
  //   component: () => import("../views/music.vue"),
  // },
];

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.name == null) {
    next("/login");
  } else {
    next();
  }
});
export default router;
